package linkedin;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Tzachi on 26/10/2014.
 * There is a particular sequence that only uses numbers 1, 2, 3, 4 and no two adjacent numbers are the same.
 * Write a program that given n1 1s, n2 2s, n3 3s, n4 4s will output the number of such sequences using all these numbers.
 */
public class ConditionalPermutations {

    public static void allPermutations(int ones, int tows, int threes, String number, int previous) {
        if (ones == 0 && tows == 0 && threes == 0) {
            System.out.println(number);
        }
        if (ones > 0 && previous != 1) {
            allPermutations(ones - 1, tows, threes, number + "1", 1);
        }
        if (tows > 0 && previous != 2) {
            allPermutations(ones, tows - 1, threes, number + "2", 2);
        }
        if (threes > 0 && previous != 3) {
            allPermutations(ones, tows, threes - 1, number + "3", 3);
        }
    }

    public static void main(String[] args) {
        List<Integer> results = new LinkedList<>();
        allPermutations(1, 1, 2, "", -1);
    }

}
